package cn.yeziji.forum.vo.answer;

import cn.yeziji.forum.entity.ForumAnswerEntity;
import cn.yeziji.forum.utils.TimeUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 统计回答的数据
 *
 * @author gzkemays
 * @since 2022/11/26 6:05 PM
 */
@Data
public class AnswerStaticsVO {
  Integer id;
  /** 对应的日期 */
  String date;

  public AnswerStaticsVO(ForumAnswerEntity entity) {
    Date updateTime = entity.getUpdateTime();
    if (entity.getUpdateTime() == null) {
      Date createTime = entity.getCreateTime();
      this.date = TimeUtils.dateToWeek(createTime);
    } else {
      this.date = TimeUtils.dateToWeek(updateTime);
    }
  }

  public static List<AnswerStaticsVO> list(List<ForumAnswerEntity> entities) {
    List<AnswerStaticsVO> list = new ArrayList<>();
    for (ForumAnswerEntity entity : entities) {
      list.add(new AnswerStaticsVO(entity));
    }
    return list;
  }
}
